/*if (!requestScreenCapture()) {
    toast("请求截图失败");
    exit();
}
*/
function num() {
    var str = id("bbt").findOne().text();
    log(str);
    str = str.slice(5);
    return Number(str.split("\)")[0]);
}
var i = 1;

var args = engines.myEngine().execArgv;
var appName = args.appName;
var Lrsd = Number(args.Lrsd);
var Yqsd = Number(args.Yqsd);
var Lrrs = Number(args.Lrrs);

app.launchApp(appName);
sleep(500);
id("djh").waitFor();
sleep(500);
click(id("ik5").findOne().bounds());
sleep(300);
back();
sleep(500);
var Hheight = id("atu").findOne().bounds().height();
var Hy = id("atu").findOne().bounds().top;
var i = Lrrs;
while (i >= 0) {
    var fk = id("axa").find().find(checked(false));
    for (var fkl = fk.length - 1; fkl >= 0;) {
        if (i > 0) {
            click(fk[fkl].parent().bounds());
            i--;
            fkl--;
        } else if (i == 0) {
            var numJl = num();
            if (numJl == Lrrs)
                break;
            else
                i = Lrrs - numJl;
        }
        sleep(Lrsd);
    }
    if (i >= 0) {
        fk = id("axa").find().find(checked(false));
        for (var fkl = fk.length - 1; fkl >= 0; fkl--) {
            click(fk[fkl].parent().bounds());
            sleep(Lrsd);
        }
    }
    sleep(100);
    if (id("k8u").text("A").findOnce() || num() == Lrrs)
        break;
    //bounds("(0,593,1080,2145)")
    swipe(647, Hy, 647, Hy + Hheight, 200);
    sleep(300);

}
var ljyq = id("bbt").findOne().bounds();
sleep(Yqsd);
takeScreenshot();
sleep(Yqsd);
//id("axa").checked(true).findOne().text();

var Time = new Date();
var Year = Time.getFullYear();
var Month = Time.getMonth() + 1;
var Day = Time.getDate();
var Hours = Time.getHours();
var Minutes = Time.getMinutes();
var Seconds = Time.getSeconds();
var time = "[" + Year + "年" + Month + "月" + Day + "日" + Hours + ":" + Minutes + ":" + Seconds + "]";
var saveStr = time + id("ivTitleName").findOne().text() + " ：" + id("f5e").findOne().text();
files.createWithDirs("/storage/emulated/0/群and位置.txt");
var saveQ = open("/storage/emulated/0/群and位置.txt", "a");
/*var path="/storage/emulated/0/Pictures/Screenshots/"+ name;
var img = captureScreen();media.scanFile(path);
images.scanFile(img,  path);*/
click(ljyq);
id("eor").text("群聊成员").waitFor();
back();
sleep(300);
id("mam").waitFor();
while (id("mam").findOne(500)) {
    back();
    sleep(700);
}
click(id("kbi").text("我的").findOne().bounds());
var qqName = id("nickname").findOne().text();
saveQ.write(qqName + "：" + saveStr + "\n");
saveQ.close();